package main

import (
	"os"

	"gitee.com/go-wena/cli"
)

func init() {
	cli.New(
		cli.Use("completion [bash|zsh|fish|powershell]"),
		cli.Comment("Generate completion script", completionDescription),
		cli.Hidden(true),
		cli.ValidArgs("bash", "zsh", "fish", "powershell"),
		cli.ExactValidArgs(1),
		cli.Run(func(c *cli.Command, args []string) {
			if len(args) > 0 {
				switch args[0] {
				case "bash":
					_ = c.Root().GenBashCompletion(os.Stdout)
				case "zsh":
					_ = c.Root().GenZshCompletion(os.Stdout)
				case "fish":
					_ = c.Root().GenFishCompletion(os.Stdout, true)
				case "powershell":
					_ = c.Root().GenPowerShellCompletion(os.Stdout)
				}
			} else {
				_ = c.Help()
			}
		}),
	).AddTo(root)
}

const completionDescription = `To load completions:

Bash:

$ source <(wena completion bash)

# To load completions for each session, execute once:
Linux:
  $ wena completion bash > /etc/bash_completion.d/wena
MacOS:
  $ wena completion bash > /usr/local/etc/bash_completion.d/wena

Zsh:

# If shell completion is not already enabled in your environment you will need
# to enable it.  You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ wena completion zsh > "${fpath[1]}/_wena"

# You will need to start a new shell for this setup to take effect.

Fish:

$ wena completion fish | source

# To load completions for each session, execute once:
$ wena completion fish > ~/.config/fish/completions/wena.fish
`
